<template>
	<view>
		<view class="card-title title">{{ title }}</view>
		<view v-if="hasSaleTips" class="section">
			<view class="sale_tips">
				<view class="sale_tips_item" v-for="(item, index) in sale_tips" :key="index">
					<view class="label">{{ item.title }}</view>
					<view class="content">{{ item.content }}</view>
				</view>
			</view>
		</view>
		<template v-if="hasBookingTips">
			<view class="section booking-tips-section" v-for="(item, index) in booking_tips" :key="index">
				<view class="card-title">{{ item.title }}</view>
				<view
					class="content"
					:class="{ 'booking-tips-content': bookingTipsContentToArray(item.content)?.length > 1 }"
					v-for="(str, idx) in bookingTipsContentToArray(item.content)"
					:key="idx"
				>
					{{ str }}
				</view>
			</view>
		</template>
	</view>
</template>

<script setup lang="ts">
import { computed } from "vue"
import type { SaleTips } from "@/types/ticket"

interface NoticeCardProps {
	title: string
	sale_tips: SaleTips[]
	booking_tips: SaleTips[]
}

const props = withDefaults(defineProps<NoticeCardProps>(), { title: "购买须知" })

const hasSaleTips = computed(() => !!props.sale_tips?.length)
const hasBookingTips = computed(() => !!props.booking_tips?.length)

const bookingTipsContentToArray = (str: string) => str.split("\n").filter(Boolean)
</script>

<style lang="scss" scoped>
@import "../ticket/index.scss";

.section {
	margin-bottom: 40rpx;
	padding-bottom: 40rpx;
	border-bottom: 1rpx solid #e5e6eb;
	word-break: break-all;

	&:last-child {
		margin-bottom: 0;
		padding-bottom: 0;
		border-bottom: none;
	}

	.content {
		position: relative;
		font-weight: 400;
		font-size: 28rpx;
		color: #4e5969;
		line-height: 40rpx;
	}

	.booking-tips-content {
		padding-left: 20rpx;

		&::before {
			content: "";
			position: absolute;
			left: 0;
			top: 0;
			width: 8rpx;
			height: 8rpx;
			margin-top: 16rpx;
			background: #e7e7e7;
			border-radius: 50%;
		}
	}

	.sale_tips {
		&_item {
			display: flex;
			align-items: center;
			margin-bottom: 32rpx;

			&:last-child {
				margin-bottom: 0;
			}

			.label {
				min-width: 112rpx;
				padding: 6rpx 8rpx 4rpx;
				border-radius: 8rpx;
				border: 1rpx solid #e5e6eb;
				text-align: center;
				font-weight: 400;
				font-size: 24rpx;
				color: #1d2129;
				line-height: 36rpx;
			}

			.content {
				margin-left: 24rpx;
			}
		}
	}
}

.booking-tips-section {
	padding-bottom: 32rpx;

	&:last-child {
		padding-bottom: 0;
	}
}
</style>
